package com.spirng.leetcode.day08;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Test17 {
    public static void main(String[] args) {
        Test17 test17 = new Test17();
        test17.letterCombinations("23");
    }
    HashMap<Character,String> map=new HashMap<>();
    ArrayList arrayList=new ArrayList<String>();
    public List<String> letterCombinations(String digits) {
        map.put('2', "abc");
        map.put('3', "def");
        map.put('4', "ghi");
        map.put('5',"jkl");
        map.put('6',"mno");
        map.put('7',"pqrs");
        map.put('8',"tuv");
        map.put('9',"wxyz");
        char[] digitsCharArray = digits.toCharArray();
        backtracking(digitsCharArray,0,"");
        return arrayList;
    }
    public void backtracking(char[] digits,int offSize,String res){
        if(offSize> digits.length-1&&res.length()==digits.length){
            arrayList.add(new String(res));
            return;
        }
        if(offSize> digits.length-1){
            return;
        }
        String s = map.get(digits[offSize]);
        char[] charArray1 = s.toCharArray();
        for (char c1 : charArray1) {
                res=res+c1;
                backtracking(digits,offSize+1,res);
                res=res.substring(0,res.length()-1);
            }

    }
}
